<div class="page-group">
	<div class="page" >
   <header class="bar bar-nav">
        <a onclick="window.history.go(-1);"class="icon" style="width: 40%">
            <img src="__PUBLIC__/img/iconfont_back@2x.png" class="back_img">
        </a>
    </header> 
    <div class="content">
    		<div style="background: #FFF;width: 100%;padding: 10px">
		          <div class="buttons-row" style="width: 50%;text-align: center;margin: auto">
				    <a href="#tab1" class="tab-link active button" id="tab1" onclick="showcharge(1)">会员充值</a>
				    <a href="#tab2" class="tab-link button" id="tab2" onclick="showcharge(2)">会员续费</a>
				  </div>
		  </div>
		  	<div style="padding: 10px;background: #FFF;margin-top: 10px">
		  		<img src="{$headimgurl}" style="width: 50px;height: 50px;border-radius:50%">
				<if condition="$expire_time lt '1970-02-01 00:00:00'">
					<span style="float: right;line-height:50px;">非会员</span>
					<else />
					<span style="float: right;line-height:50px;">{$expire_time|strtotime|date="Y/m/d",###}到期</span>
				</if>

		  	</div>
		  	<div style="background: #FFF;padding: 5px" id="charge1">
				<volist name="dt" id="v">
					<div class="vip_charge">
						<span class="font14">开通<font class="font16 color_book_kind_titile" style="margin:0rem;">{$v.month}</font>个月豪华付费会员</span>
						<span class="font14">{$v.price}元</span>
						<span><input class="font14 btn_vip_charge" style="float:right" type="button" value="充值" onclick="charge({$v.type_id})"></span>
					</div>
				</volist>
		  	</div>
			<div style="background: #FFF;padding: 5px;display:none;" id="charge2">
				<volist name="dt" id="v">
					<div class="vip_charge">
						<span class="font14">开通<font class="font16 color_book_kind_titile"  style="margin:0rem;">{$v.month}</font>个月豪华付费会员</span>
						<span class="font14">{$v.price}元</span>
						<span><input class="font14 btn_vip_charge" style="float:right" type="button" value="续费" onclick="charge({$v.type_id})"></span>
					</div>
				</volist>
			</div>
    </div>
</div>
</div>
<script>
	function showcharge($id){
		$(".active").attr("Class","tab-link button");
		$("#tab"+$id).attr("Class","tab-link button active");
		$("#charge1").hide();
		$("#charge2").hide();
		$("#charge"+$id).show();
	}
	//发起充值-产生订单
	function charge($id){
		$.post("{:U('Order/bear_order_vip')}",{id:$id},function(data){
			Unifiedorder(data);
		});
	}
	//统一下单
	function Unifiedorder($pay_id){
		$.post("{:U('Order/getJsApiParameters_vip')}",{id:$pay_id},function(data){
			var data= eval('(' + data + ')');
			if(data.status=="error"){
				alert("无法支付，"+data.message);
			}
			if(data.status=="success"){
				callpay(data.message);
			}
		});
	}

	//微信支付
	function callpay(data)
	{
		if (typeof WeixinJSBridge == "undefined"){
			if( document.addEventListener ){
				document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
			}else if (document.attachEvent){
				document.attachEvent('WeixinJSBridgeReady', jsApiCall);
				document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
			}
		}else{
			jsApiCall(data);
		}
	}

	function jsApiCall($jsApiParameters)
	{
		WeixinJSBridge.invoke(
				'getBrandWCPayRequest',
				eval('(' + $jsApiParameters + ')'),
				function(res){
					WeixinJSBridge.log(res.err_msg);
//					alert(res.err_code+res.err_desc+res.err_msg);
					window.location='{:U("Vip/index")}';
				}
		);
	}

</script>
</body>
</html>